//
//  Singleton.m
//  UI11_Address
//
//  Created by dllo on 15/10/23.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "Singleton.h"
#import "Students.h"
@implementation Singleton

- (void)dealloc
{
    [_allKeysArray release];
    [_studentDic release];
    [super dealloc];
}


+(instancetype)shareSingleton
{
    static Singleton *singleton = nil;
    if (singleton == nil) {
        singleton = [[Singleton alloc]init];
        
        [singleton createStudentDic];
    }
    return singleton;
}

-(void)createStudentDic
{
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Student" ofType:@"plist"];
    NSMutableDictionary *bigDic = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
    
    self.studentDic = [NSMutableDictionary dictionary];
    
    for (NSString *key in bigDic) {
        NSArray *array = [bigDic objectForKey:key];
        NSMutableArray *stuArray = [NSMutableArray array];
        for (NSMutableDictionary *dic in array) {
            Students *stu = [[Students alloc]init];
            [stu setValuesForKeysWithDictionary:dic];
            
            [stuArray addObject:stu];
            [stu release];
        }
        [self.studentDic setObject:stuArray forKey:key];
//        NSLog(@"%@",self.studentDic);
    }
    self.allKeysArray = [NSMutableArray arrayWithArray:self.studentDic.allKeys];
    [self.allKeysArray sortUsingSelector:@selector(compare:)];
}




@end
